using UnityEngine;
using System.Collections;

public class BSP_Rectangle
{
	public int x;
	public int y;
	public int width;
	public int height;
	public int right;
	public int bottom;
	
	public BSP_Rectangle()
	{
		this.x = 0;
		this.y = 0;
		this.width = 0;
		this.height = 0;
		this.right = 0;
		this.bottom = 0;
	}
	
	public BSP_Rectangle(int newX, int newY, int w, int h)
	{
		this.x = newX;
		this.y = newY;
		this.width = w;
		this.height = h;
		this.updateRect();
	}

	public BSP_Rectangle copyRectangle()
	{
		return new BSP_Rectangle(this.x,this.y,this.width,this.height);
	}
	
	public void updateRect()
	{
		this.right = this.x + this.width;
		this.bottom = this.y + this.height;
	}			
	
	public bool intersects(BSP_Rectangle other)
	{
		int inLeft = Mathf.Max(this.x, other.x);
		int inRight = Mathf.Min(this.right, other.right);
		int inTop = Mathf.Max(this.y, other.y);
		int inBottom = Mathf.Min(this.bottom, other.bottom);
		
		return (inRight > inLeft && inBottom > inTop);
	}
	
	public bool contains(BSP_Rectangle other)
	{
	    bool pointOne = false;
        bool pointTwo = false;
        bool pointThree = false;
        bool pointFour = false;
        
        if(other.x > this.x &&
           other.x < this.x + this.width &&
           other.y > this.y &&
           other.y < this.y + this.height) pointOne = true;
           
        if(other.x + other.width > this.x &&
           other.x + other.width < this.x + this.width &&
           other.y > this.y &&
           other.y < this.y + this.height) pointTwo = true;
           
                      
        if(other.x > this.x &&
           other.x < this.x + this.width &&
           other.y + other.height > this.y &&
           other.y + other.height < this.y + this.height) pointThree = true;  
                
           
        if(other.x + other.width > this.x &&
           other.x + other.width < this.x + this.width &&
           other.y + other.height > this.y &&
           other.y + other.height < this.y + this.height) pointFour = true;
           
           
        return pointOne && pointTwo && pointThree && pointFour;
	}
}


